<?php
namespace ulit;
use think\Db;
use think\Session;
class CryptAES

{
    const  IV = 'AESAPPCLIENT_KEY';//16或16的倍数长个char

    const key= 'JF_2022610000000';

//$privateKey是加密 解密需要的密钥
   public   function  aesEncode($data, $privateKey=self::key,$iv=self::IV): string
   {

        $encrypted =openssl_encrypt($data,"AES-128-CBC",$privateKey,OPENSSL_RAW_DATA,$iv);
        return rtrim((base64_encode($encrypted)));
    }

    public    function aesDecode($data, $privateKey=self::key,$iv=self::IV): string
    {
        $decrypted =  openssl_decrypt(base64_decode($data),"AES-128-CBC",$privateKey,OPENSSL_RAW_DATA,$iv);
        return rtrim($decrypted);
    }
}


